<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
 lang="en" dir="ltr">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link rel="stylesheet" href="../codebase/default.css" type="text/css" media="screen" title="no title" charset="utf-8"><title>
    dhtmlxdataprocessor:common_tasks    [Skin test wiki]
  </title></head>

<body>
<div class="dokuwiki">
  
  <div class="stylehead">

    <div class="header">
    <a class="logo" href="http://dhtmlx.com" title="DHTMLX Documentation homepage"></a>
    <span class="tittle-dhtmlx">DHTMLX Docs & Samples Explorer</span>

    <div class="search-field">
        <form action="http://dhtmlx.com/dhxdocs/doku.php" accept-charset="utf-8" id="dw__search"><div class="no"><input type="hidden" name="do" value="search" /><input type="text" id="qsearch__in" accesskey="f" name="id" title="Search" /><button type="submit"></button><div id="qsearch__out" class="ajax_qsearch JSpopup"></div></div></form>    </div>
        <div class="buttons">
                <a class="doc"></a>
                <a title="DHTMLX Samples homepage" href="../samples.html" class="sample"/></a>
        </div>
     <!-- <div class="pagename">
        [[<a href="#"  title="Backlinks">dhtmlxdataprocessor:common_tasks</a>]]
      </div>
      <div class="logo">
        <a href="/dhtmlx/_lab/wiki/doku.php"  name="dokuwiki__top" id="dokuwiki__top" accesskey="h" title="[H]">Skin test wiki</a>      </div>

      <div class="clearer"></div>-->
        
    </div>

    
<!--   <div class="bar" id="bar__top">
      <div class="bar-left" id="bar__topleft">
                <form class="button btn_revs" method="get" action="http://dhtmlx.com/dhxdocs/doku.php"><div class="no"><input type="hidden" name="do" value="revisions" /><input type="hidden" name="id" value="dhtmlxdataprocessor:common_tasks" /><input type="submit" value="Old revisions" class="button" accesskey="o" title="Old revisions [O]" /></div></form>      </div>

      <div class="bar-right" id="bar__topright">
        <form class="button btn_recent" method="get" action="http://dhtmlx.com/dhxdocs/doku.php"><div class="no"><input type="hidden" name="do" value="recent" /><input type="hidden" name="id" value="dhtmlxdataprocessor:common_tasks" /><input type="submit" value="Recent changes" class="button" accesskey="r" title="Recent changes [R]" /></div></form>        <form action="http://dhtmlx.com/dhxdocs/doku.php" accept-charset="utf-8" id="dw__search"><div class="no"><input type="hidden" name="do" value="search" /><input type="text" id="qsearch__in" accesskey="f" name="id" title="Search" /><button type="submit"></button><div id="qsearch__out" class="ajax_qsearch JSpopup"></div></div></form>&nbsp;
      </div>

      <div class="clearer"></div>
    </div> -->

<!--        <div class="breadcrumbs">
      <span class="bchead">Trace:</span> <span class="bcsep">&raquo;</span> <span class="curid"><a href="/dhtmlx/_lab/wiki/doku.php?id=dhtmlxdataprocessor:common_tasks"  class="breadcrumbs" title="dhtmlxdataprocessor:common_tasks">common_tasks</a></span>    </div>
    -->

    
  </div>
  
  
  <div class="page">
    <!-- wikipage start -->
    
<p>
<div class='backlinks'><div class='backlink last_backlink'><img src="icons___file.gif"  class="media" alt="" /><a href="../index.html" class="wikilink1" title="start">Index</a></div><div class='arrow'></div><div class='backlink last_backlink'><img src="icons___dataprocessor.gif"  class="media" alt="" /><a href="index.html" class="wikilink1" title="dhtmlxdataprocessor:toc">dhtmlxdataprocessor</a></div><div class='arrow'></div><div class='backlink'><span class="curid"><a href="dhtmlxdataprocessor___common_tasks.html" class="wikilink1" title="dhtmlxdataprocessor:common_tasks"> Common Tasks </a></span></div></div>

</p>

<h2><a name="common_tasks" id="common_tasks">Common Tasks</a></h2>
<div class="level2">

<p>

a) Waiting for finishing update.
There are two events which can be used to catch finish of data sync operation:

</p>
<pre class="code javascript">  dp.<span class="me1">attachEvent</span><span class="br0">&#40;</span><span class="st0">&quot;onAfterUpdateFinish&quot;</span><span class="sy0">,</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
      <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;single row updated&quot;</span><span class="br0">&#41;</span>
  <span class="br0">&#125;</span><span class="br0">&#41;</span>;
  dp.<span class="me1">attachEvent</span><span class="br0">&#40;</span><span class="st0">&quot;onFullSync&quot;</span><span class="sy0">,</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
      <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;all rows updated&quot;</span><span class="br0">&#41;</span>
  <span class="br0">&#125;</span><span class="br0">&#41;</span>;</pre>
<p>

In any moment of time update state can be checked as follows:

</p>
<pre class="code javascript">  dp.<span class="me1">getSyncState</span><span class="br0">&#40;</span><span class="br0">&#41;</span></pre>
<p>

which will return true if all data synced with server and false otherwise
</p>

<p>
b) Manual row updating.
The dataprocessor detects the row changed only by edit operations. If a row was changed by a direct <acronym title="Application Programming Interface">API</acronym> calling it will not be updated. You can manually call the dataprocessor to inform about the update operation:

</p>
<pre class="code javascript">      grid.<a href='dhtmlxgrid___api_method_dhtmlxgridobject_cells.html'><b><span class="me1">cells</span></b></a><span class="br0">&#40;</span>id<span class="sy0">,</span>ind<span class="br0">&#41;</span>.<span class="me1">setValue</span><span class="br0">&#40;</span>new_one<span class="br0">&#41;</span>
      dp.<span class="me1">setUpdated</span><span class="br0">&#40;</span>id<span class="sy0">,</span><span class="kw2">true</span><span class="br0">&#41;</span>;</pre>
<p>

The row can be marked as “not updated” in the same manner (may be useful in some scenarios):

</p>
<pre class="code javascript">      dp.<span class="me1">setUpdated</span><span class="br0">&#40;</span>id<span class="sy0">,</span><span class="kw2">false</span><span class="br0">&#41;</span>;</pre>
<p>

If you want to mark row with status different from “updated” (not sure how it can be useful, but still ) it can be done as below:

</p>
<pre class="code javascript">       dp.<span class="me1">setUpdated</span><span class="br0">&#40;</span>id<span class="sy0">,</span><span class="kw2">true</span><span class="sy0">,</span><span class="st0">&quot;status name&quot;</span><span class="br0">&#41;</span>;</pre>
<p>

c) Error catching.
</p>

<p>
Starting version 2.1, dataprocessor has default reaction on “error” response type, which can be used to report about server side errors. Row marked as error will be highlighted in grid. And it will not be sent back to server until one of the next events occurs:
</p>
<ul>
<li class="level1"><div class="li"> user edit data in row;</div>
</li>
<li class="level1"><div class="li"> rows set back to updated status through setUpdated command.</div>
</li>
</ul>

<p>

d) Sever side validation.
</p>

<p>
There is a built in support for “invalid” status in server side response. It&#039;s similar to “error”, but has different visual marking.
</p>

<p>
If you want to extend it, you should do the following:

</p>
<pre class="code javascript">  dp.<span class="me1">defineAction</span><span class="br0">&#40;</span><span class="st0">&quot;invalid&quot;</span><span class="sy0">,</span><span class="kw2">function</span><span class="br0">&#40;</span>sid<span class="sy0">,</span>response<span class="br0">&#41;</span><span class="br0">&#123;</span>
            <span class="kw2">var</span> message <span class="sy0">=</span> response.<span class="me1">getAttribute</span><span class="br0">&#40;</span><span class="st0">&quot;message&quot;</span><span class="br0">&#41;</span>;
            <span class="kw3">alert</span><span class="br0">&#40;</span>message<span class="br0">&#41;</span>;
&nbsp;
&nbsp;
&nbsp;
            <span class="kw1">return</span> <span class="kw2">true</span>;
  <span class="br0">&#125;</span><span class="br0">&#41;</span></pre>
<p>

now you can do the next on server side, if data is not valid you can just output the next instead of valid response:

</p>
<pre class="code javascript"><span class="sy0">&lt;</span>data<span class="sy0">&gt;</span>
 <span class="sy0">&lt;</span>action sid<span class="sy0">=</span><span class="st0">&quot;{gr_id}&quot;</span> type<span class="sy0">=</span><span class="st0">&quot;invalid&quot;</span> message<span class="sy0">=</span><span class="st0">&quot;Data in first column is not valid&quot;</span> <span class="sy0">/&gt;</span>
 <span class="sy0">&lt;/</span>data<span class="sy0">&gt;</span></pre>
<p>

e) Loading extra data during update.
</p>

<p>

It&#039;s possible to extend default after-update reaction as:

</p>
<pre class="code javascript">  dp.<span class="me1">defineAction</span><span class="br0">&#40;</span><span class="st0">&quot;updated&quot;</span><span class="sy0">,</span><span class="kw2">function</span><span class="br0">&#40;</span>sid<span class="sy0">,</span>response<span class="br0">&#41;</span><span class="br0">&#123;</span>
            <span class="kw2">var</span> sid <span class="sy0">=</span> response.<span class="me1">getAttribute</span><span class="br0">&#40;</span><span class="st0">&quot;sid&quot;</span><span class="br0">&#41;</span>;
            <span class="kw2">var</span> extra <span class="sy0">=</span> response.<span class="me1">getAttribute</span><span class="br0">&#40;</span><span class="st0">&quot;extra&quot;</span><span class="br0">&#41;</span>;
            <span class="kw1">this</span>.<span class="me1">obj</span>.<span class="me1">cells</span><span class="br0">&#40;</span>id<span class="sy0">,</span>0<span class="br0">&#41;</span>.<span class="me1">setValue</span><span class="br0">&#40;</span>extra<span class="br0">&#41;</span>;
            <span class="kw1">return</span> <span class="kw2">true</span>;
  <span class="br0">&#125;</span><span class="br0">&#41;</span></pre>
<p>

with such code you will be able to specify any additional data which needs to be updated in grid after receiving xml response from the server:

</p>
<pre class="code javascript"><span class="sy0">&lt;</span>data<span class="sy0">&gt;</span>
 <span class="sy0">&lt;</span>action sid<span class="sy0">=</span><span class="st0">&quot;{gr_id}&quot;</span> type<span class="sy0">=</span><span class="st0">&quot;updated&quot;</span> tid<span class="sy0">=</span><span class="st0">&quot;{gr_id}&quot;</span> extra<span class="sy0">=</span><span class="st0">&quot;new value for first column&quot;</span> <span class="sy0">/&gt;</span>
 <span class="sy0">&lt;/</span>data<span class="sy0">&gt;</span></pre>
</div>

    <!-- wikipage stop -->
  </div>

  <div class="clearer">&nbsp;</div>

  
  <div class="stylefoot">

    <div class="meta">
      <div class="user">
              </div>
     <!-- <div class="doc">
        dhtmlxdataprocessor/common_tasks.txt &middot; Last modified: 2009/07/30 12:56 (external edit)      </div>
    </div>-->

   
    <!--<div class="bar" id="bar__bottom">-->
      <!--<div class="bar-left" id="bar__bottomleft">-->
        <!---->
        <!--<form class="button btn_revs" method="get" action="http://dhtmlx.com/dhxdocs/doku.php"><div class="no"><input type="hidden" name="do" value="revisions" /><input type="hidden" name="id" value="dhtmlxdataprocessor:common_tasks" /><input type="submit" value="Old revisions" class="button" accesskey="o" title="Old revisions [O]" /></div></form>-->
      <!--</div>-->
      <!--<div class="bar-right" id="bar__bottomright">-->
        <!---->
        <!---->
        <!---->
        <!---->
        <!--<form class="button btn_login" method="get" action="http://dhtmlx.com/dhxdocs/doku.php"><div class="no"><input type="hidden" name="do" value="login" /><input type="hidden" name="sectok" value="1eda4ff47ac03400a562708d3d147d27" /><input type="hidden" name="id" value="dhtmlxdataprocessor:common_tasks" /><input type="submit" value="Login" class="button" title="Login" /></div></form>-->
        <!--<form class="button btn_index" method="get" action="http://dhtmlx.com/dhxdocs/doku.php"><div class="no"><input type="hidden" name="do" value="index" /><input type="hidden" name="id" value="dhtmlxdataprocessor:common_tasks" /><input type="submit" value="Index" class="button" accesskey="x" title="Index [X]" /></div></form>-->
        <!--<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="Back to top" onclick="window.scrollTo(0, 0)" title="Back to top" /></a>&nbsp;-->
      <!--</div>-->
      <!--<div class="clearer"></div>-->
    <!--</div>-->

  </div>

  

</div>

<div class="footerinc">


</div>

<div class="no"><img src="/dhtmlx/_lab/wiki/lib/exe/indexer.php?id=dhtmlxdataprocessor%3Acommon_tasks&amp;1257951057" width="1" height="1" alt=""  /></div>
     <div class="footer">
        <div class="footer-logo"></div>
        <div class="copyright">Copyright © 1998-2009 DHTMLX LTD.<br />All rights reserved.</div>
            	    </div>
</body>
</html>
